package com.example.project.service.impl;

import com.example.project.dao.TcdmSecureHazardListDao;
import com.example.project.entity.TcdmSecureHazardList;
import com.example.project.entity.TcdmSecureHazardListRecycle;
import com.example.project.dao.TcdmSecureHazardListRecycleDao;
import com.example.project.service.TcdmSecureHazardListRecycleService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TcdmSecureHazardListRecycle)表服务实现类
 *
 * @author makejava
 * @since 2024-02-23 15:18:23
 */
@Service("tcdmSecureHazardListRecycleService")
public class TcdmSecureHazardListRecycleServiceImpl implements TcdmSecureHazardListRecycleService {
    @Resource
    private TcdmSecureHazardListRecycleDao tcdmSecureHazardListRecycleDao;
    @Resource
    private TcdmSecureHazardListDao tcdmSecureHazardListDao;
    /**
     * 通过ID查询单条数据
     *
     * @param tshlrId 主键
     * @return 实例对象
     */
    @Override
    public TcdmSecureHazardListRecycle queryById(Integer tshlrId) {
        return this.tcdmSecureHazardListRecycleDao.queryById(tshlrId);
    }

    @Override
    public List<TcdmSecureHazardListRecycle> findList() {
        return this.tcdmSecureHazardListRecycleDao.findList();
    }

    /**
     * 分页查询
     *
     * @param tcdmSecureHazardListRecycle 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TcdmSecureHazardListRecycle> queryByPage(TcdmSecureHazardListRecycle tcdmSecureHazardListRecycle, PageRequest pageRequest) {
        long total = this.tcdmSecureHazardListRecycleDao.count(tcdmSecureHazardListRecycle);
        return new PageImpl<>(this.tcdmSecureHazardListRecycleDao.queryAllByLimit(tcdmSecureHazardListRecycle, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tcdmSecureHazardListRecycle 实例对象
     * @return 实例对象
     */
    @Override
    public TcdmSecureHazardListRecycle insert(TcdmSecureHazardListRecycle tcdmSecureHazardListRecycle) {
        this.tcdmSecureHazardListRecycleDao.insert(tcdmSecureHazardListRecycle);
        return tcdmSecureHazardListRecycle;
    }

    /**
     * 修改数据
     *
     * @param tcdmSecureHazardListRecycle 实例对象
     * @return 实例对象
     */
    @Override
    public TcdmSecureHazardListRecycle update(TcdmSecureHazardListRecycle tcdmSecureHazardListRecycle) {
        this.tcdmSecureHazardListRecycleDao.update(tcdmSecureHazardListRecycle);
        return this.queryById(tcdmSecureHazardListRecycle.getTshlrId());
    }

    /**
     * 通过主键删除数据
     *
     * @param tshlrId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer tshlrId) {
        return this.tcdmSecureHazardListRecycleDao.deleteById(tshlrId) > 0;
    }

    @Override
    public Boolean deleteById1(Integer tshlrId) {
        TcdmSecureHazardListRecycle tcdmSecureHazardListRecycle=this.tcdmSecureHazardListRecycleDao.queryById(tshlrId);
        this.tcdmSecureHazardListDao.deleteById(tcdmSecureHazardListRecycle.getTshaId());
        return this.tcdmSecureHazardListRecycleDao.deleteById(tshlrId)>0;
    }

    @Override
    public Boolean recover(Integer tshlrId) {
        TcdmSecureHazardListRecycle tcdmSecureHazardListRecycle=this.tcdmSecureHazardListRecycleDao.queryById(tshlrId);
        TcdmSecureHazardList tcdmSecureHazardList=new TcdmSecureHazardList();
        tcdmSecureHazardList.setTshlId(tcdmSecureHazardListRecycle.getTshaId());
        tcdmSecureHazardList.setValid(1);
        this.tcdmSecureHazardListDao.update(tcdmSecureHazardList);

        return this.tcdmSecureHazardListRecycleDao.deleteById(tshlrId)>0;
    }

    @Override
    public Boolean deleteAll() {
        this.tcdmSecureHazardListDao.deleteByValid();
        return this.tcdmSecureHazardListRecycleDao.deleteAll();
    }
}
